spinlock: improve spin_is_locked() for recursive locks
authorJan Beulich <jbeulich@suse.com>
Tue, 29 Mar 2016 15:16:23 +0000 (17:16 +0200)
committerJan Beulich <jbeulich@suse.com>
Tue, 29 Mar 2016 15:16:23 +0000 (17:16 +0200)
Recursive locks know their current owner, and since we use the function
solely to determine whether a particular lock is being held by the
current CPU (which so far has been an imprecise check), make actually
check the owner for recusrively acquired locks.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Dario Faggioli <dario.faggioli@citrix.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Quan Xu <quan.xu@intel.com>
Acked-by: Tim Deegan <tim@xen.org>
xen/common/spinlock.c

index a43fa84f5b206f5e548296629de27e50f400d100..b377bb907b0d46ae3e129905792106ea5108e55b 100644 (file)
@@ -188,7 +188,15 @@ void _spin_unlock_irqrestore(spinlock_t *lock, unsigned long flags)
 int _spin_is_locked(spinlock_t *lock)
 {
     check_lock(&lock->debug);
-    return lock->tickets.head != lock->tickets.tail;
+
+    /*
+     * Recursive locks may be locked by another CPU, yet we return
+     * "false" here, making this function suitable only for use in
+     * ASSERT()s and alike.
+     */
+    return lock->recurse_cpu == SPINLOCK_NO_CPU
+           ? lock->tickets.head != lock->tickets.tail
+           : lock->recurse_cpu == smp_processor_id();
 }
 
 int _spin_trylock(spinlock_t *lock)